package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseAttrValue;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/8/26 23:05
 */
@Api(tags = "商品属性管理")
@RestController
@RequestMapping("/admin/product")
public class BaseAttrInfoController {
    @Autowired
    private BaseAttrInfoService baseAttrInfoService;
    @ApiOperation(value = "获取商品属性列表")
    @GetMapping("/attrInfoList/{categoryId1}/{categoryId2}/{categoryId3}")
    public Result getBaseAttrInfo(@PathVariable("categoryId1") Long categoryId1,
                                  @PathVariable("categoryId2") Long categoryId2,
                                  @PathVariable("categoryId3") Long categoryId3) {
        List<BaseAttrInfo> baseAttrInfo = baseAttrInfoService.getBaseAttrInfo(categoryId1, categoryId2, categoryId3);
        return Result.ok(baseAttrInfo);
    }
    //第一次保存是新增,非第一次保存是修改
    @PostMapping("/saveAttrInfo")
    public Result saveBaseAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo) {
        //baseAttrInfoService.saveBaseAttrInfo(baseAttrInfo);
        baseAttrInfoService.saveOrUpdateAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable("attrId") Long attrId) {
        List<BaseAttrValue> attrValueList = baseAttrInfoService.getAttrValueList(attrId);
        return Result.ok(attrValueList);
    }
}
